//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "tyr_artillery\fn_onload.sqf"
#include <core_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

private ["_counter","_mags","_cfgmagx","_xammo","_ari_vecs","_vvx","_i","_ammos","_x"];

disableSerialization;

lbclear 1251;
lbclear 1252;

_ari_vecs = [];
for "_i" from 0 to 20 do {
	_vvx = missionNamespace getVariable format ["tyr_arty_%1_%2", str(playerSide), _i];
	if (!isNil "_vvx") then {
		_ari_vecs set [count _ari_vecs, _vvx];
	};
};

_mags = [];
_ammos = [];
if (count _ari_vecs <= 0) then {
	_mags = GVAR(DEFAULT_AMMUNITIONS);
} else {
	_cfgmagx = configFile/"CfgMagazines";
	{
		if !(_x in _mags) then {
			_xammo = getText(_cfgmagx/_x/"ammo");
			if (getText(configFile/"CfgAmmo"/_xammo/"submunitionAmmo") != "Mo_ClassicMineRange") then {
				_mags set [count _mags, _x];
			};
		};
	} forEach getArray(configFile/"CfgVehicles"/typeOf _warty/"Turrets"/"MainTurret"/"magazines");
};
_ammos resize (count _mags);
{
	_ammos set [_forEachIndex, getText(configFile/"CfgMagazines"/_x/"displayName")];
} forEach _mags;

_counter = 0;
for "_i" from 0 to ((count _mags) - 1) step 1 do {
	lbAdd [1251,(_ammos select _i)];
	lbSetData [1251,_counter,(_mags select _i)];
	INC(_counter);
};
lbSetCurSel [1251,0];

_counter = 0;
{
	lbAdd [1252,str(_x)];
	lbSetData [1252,_counter,str(_x)];
	INC(_counter);
} forEach GVAR(NUMBER_SALVOS);
lbSetCurSel [1252,0];

TRACE("End");
TMFPROFILERSTOP;